using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace FlexExplorer
{
	//public delegate void AdvanceDelegate(int step);
	//public delegate void CloseDelegate();

	public partial class MoveProgressForm : Form
	{
		private bool userClose = true;
		private Thread moveThread;

		public MoveProgressForm(Thread thread)
		{
			InitializeComponent();
			moveThread = thread;
		}

		public void SetFileLength(int size)
		{
			if (this.InvokeRequired)
			{
				this.Invoke(new AdvanceDelegate(SetFileLength),
							new object[] { size });
				return;
			}

			moveProgressBar.Minimum = 0;	
			moveProgressBar.Maximum = size;
			moveProgressBar.Value = 0;
		}

		public void Advance(int step)
		{

			if (this.InvokeRequired)
			{
				this.Invoke(new AdvanceDelegate(Advance),
							new object[] { step });
				return;
			}

			moveProgressBar.Step = step;
			moveProgressBar.PerformStep();
		}

		public void SetLabel(string labelText)
		{
			if (this.InvokeRequired)
			{
				this.Invoke(new SetLabelDelegate(SetLabel),
							new object[] { labelText });
			}

			MoveFileNameLabel.Text = labelText;
		}

		public void SetFullMovefileSizeLabel(string labelText)
		{
			if (this.InvokeRequired)
			{
				this.Invoke(new SetLabelDelegate(SetFullMovefileSizeLabel),
							new object[] { labelText });
			}

			FullMovefileSizeLabel.Text = labelText;
		}

		public void SetMovedFileSizeLabel(string labelText)
		{
			if (this.InvokeRequired)
			{
				this.Invoke(new SetLabelDelegate(SetMovedFileSizeLabel),
							new object[] { labelText });
			}
			
			MovedFileSizeLabel.Text = labelText;
		}

		public void SetMovePercentsCompleteLabel(string labelText)
		{
			if (this.InvokeRequired)
			{
				this.Invoke(new SetLabelDelegate(SetMovePercentsCompleteLabel),
							new object[] { labelText });
			}

			MovePercentsCompleteLabel.Text = labelText;
		}

		public void DoClose()
		{
			if (this.InvokeRequired)
			{
				this.Invoke(new CloseDelegate(DoClose));
				return;
			}

			userClose = false;
			Close();
		}

		private void CancelBtn_Click(object sender, EventArgs e)
		{
			Close();
		}

		private void MoveProgressForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (userClose)
			{
				moveThread.Abort();
			}
		}		
	}
}